REM ********************************************************************
REM ********************************************************************
REM ISO calibration OneCard script file				
REM Version: 0.0010				
REM arguments:				
REM     DIFF_COLOR_RATIO_LV is criteria of liveview mode for factory process; 0:read data from NAND flash, 1:write data to NAND flash(read from sd card)				
REM     DIFF_COLOR_RATIO_TK is criteria of take mode for factory process;				
REM     DIFF_COLOR_RATIO_VGA is criteria of vga mode for factory process;				
REM     IS_OUTPUT_FIG is whether output big_lamp.fig and small_lamp.fig or not? 1:yes, 0:no				
REM     IS_OUTPUT_K_RESULT is whether output k_result.txt or not? 1:yes, 0:no				
REM     IS_OUTPUT_ISO_REPORT is whether output iso_report.txt or not? 1:yes, 0:no				
REM     Select is function selection
REM ***
REM ********************************************************************				

5   SYSTEM KeyEventDisable()
6   FOREIGN PowerSaving(0)

10	LET	return=1
12	LET	IS_OUTPUT_FIG=0
14	LET	IS_OUTPUT_K_RESULT=1
16	LET	IS_OUTPUT_ISO_REPORT=1
18	LET	DIFF_COLOR_RATIO_LV=660
20	LET	DIFF_COLOR_RATIO_TK=660
22	LET	DIFF_COLOR_RATIO_VGA=660
24	LET	Select=1
26	FOREIGN	return=AEAWB_ISO100Calibration(Select,IS_OUTPUT_FIG, IS_OUTPUT_K_RESULT, IS_OUTPUT_ISO_REPORT,  DIFF_COLOR_RATIO_LV, DIFF_COLOR_RATIO_TK, DIFF_COLOR_RATIO_VGA)

28  LET	Select=7
30  LET LampNum = 0
32  FOREIGN LampNum = OneCard_ExtIndex()
REM 34  LET LampNum = LampNum+1 
36	FOREIGN	return = AEAWB_ISO100Calibration(Select,LampNum,0,0,0,0,0)
37  LET Select=2
40  FOREIGN return = AEAWB_ISO100Calibration(Select,7,0,6000,0,0,9067)
41  FOREIGN return = AEAWB_ISO100Calibration(Select,7,1,6000,0,0,9067)
42  FOREIGN return = AEAWB_ISO100Calibration(Select,7,2,6000,0,0,9067)
43  FOREIGN return = AEAWB_ISO100Calibration(Select,7,3,6000,0,0,9067)
44  FOREIGN return = AEAWB_ISO100Calibration(Select,7,4,6000,0,0,9067)

100	LET	Select = 0
110	FOREIGN	return = AEAWB_ISO100Calibration(Select,2,0,0,0,0,0)
120	LET	Select = -2
121	FOREIGN	return = AEAWB_ISO100Calibration(Select,0,0,0,0,0,0)
122 IF return == 0 THEN 200 ELSE 130

REM *****Fail case*****
130 SYSTEM KeyEventEnable()
140 LET StrISO = "ISO NG!! "+return
150 FOREIGN Ret = OneCard_FlgSet(0)
155 FOREIGN KeyReview(0)
REM 160 FOREIGN Ret = OneCard_ErrPrint(StrISO)
160 FOREIGN OneCard_ErrCodePrint(return)
170 GOTO 1000


REM *****************************************
REM *****************************************
REM -----------DBP Test-----------
REM *****************************************
200 LET YES  = 1
210 LET NO   = 0
220 LET lcdprint = "DBP Start"
230 SYSTEM ScreenString(40,60,lcdprint)
240 SYSTEM delay_us(1000000)

REM ****** Calibration Initialization *************************************
REM 250 LET Str = "DBP NG!!"
260 LET Loop             = 1
270 LET Picture_Quantity = 1
280 LET Threshold        = 10
290 LET SaveRaw          = NO
300 LET SavePosition     = NO
310 LET DumpDBP          = NO
320 LET ClearDBP         = NO
REM ****** WARM UP ********************************************************

REM ****** WARM UP END *****************************************************
330 FOREIGN ReturnValue = CBBP(Picture_Quantity, Threshold, SaveRaw, SavePosition, DumpDBP, ClearDBP)
331 LET StrDBP = "DBP NG!!" + ReturnValue
340 IF ReturnValue == 0 THEN 400 ELSE 350
REM 340 IF ReturnValue == 0 THEN 500 ELSE 350

REM Calibration Fail
350 SYSTEM KeyEventEnable()
360 FOREIGN Ret = OneCard_FlgSet(0)
365 FOREIGN KeyReview(0)
REM 370 FOREIGN Ret = OneCard_ErrPrint(StrDBP)
370 FOREIGN OneCard_ErrCodePrint(ReturnValue)
REM 380 END
380 GOTO 1000

REM *****************************************
REM still vertical line calibration start
REM *****************************************
400 LET lcdprint = "VL_Detect Start"
401 SYSTEM ScreenString(40,60,lcdprint)
402 SYSTEM delay_us(1000000)

REM ***** VL uses SHADING MEM *****
405 FOREIGN DisableLVShadingComp()
406 FOREIGN DisableFRShadingComp()

410 LET ISOValue = 1600
411 LET Thres = 10000
412 LET CompVL = 1
413 LET SaveNand = 1
414 LET MaxLine = 20
415 LET minISO = 400
416 LET maxISO = 1600

420 FOREIGN SetIsoSpeed(4, ISOValue)
430 FOREIGN ReturnValue = VL_DETECT(Thres, CompVL, SaveNand, MaxLine, minISO, maxISO)
440 IF ReturnValue == 0 THEN 490 ELSE 443

443 IF ReturnValue == 100 THEN 460 ELSE 446

446 IF ReturnValue == 200 THEN 470 ELSE 480

REM still vertical line calibration Fail
460 SYSTEM KeyEventEnable()
461 LET StrVLDetect = "Continuous still vertical lines"
462 FOREIGN Ret = OneCard_FlgSet(0)
463 FOREIGN KeyReview(0)
464 FOREIGN Ret = OneCard_ErrPrint(StrVLDetect)
465 GOTO 1000

470 SYSTEM KeyEventEnable()
471 LET StrVLDetect = "Exceed max still vertical lines"
472 FOREIGN Ret = OneCard_FlgSet(0)
473 FOREIGN KeyReview(0)
474 FOREIGN Ret = OneCard_ErrPrint(StrVLDetect)
475 GOTO 1000

480 SYSTEM KeyEventEnable()
481 LET StrVLDetect = "VL_Detect NG!!" + ReturnValue
482 FOREIGN Ret = OneCard_FlgSet(0)
483 FOREIGN KeyReview(0)
REM 484 FOREIGN Ret = OneCard_ErrPrint(StrVLDetect)
484 FOREIGN OneCard_ErrCodePrint(ReturnValue)
485 GOTO 1000

REM still vertical line calibration success
490 LET StrVLDetect = "VL_Detect Success"
491 SYSTEM ScreenString(40,90,StrVLDetect)
492 SYSTEM delay_us(2000000)

REM *****************************************************************************
REM ************************* Color Shading Calibration *************************
REM This is the Script file of Shading Calibration
REM Project: AA120A
REM Version: 0.1
REM Release Date: 2009/12/09
REM Author: KimiKuo
REM note: None
REM *****************************************************************************

500   LET YES = 1
501   LET NO  = 0

REM ******* Set Shading Calibration Mode *******
REM   0: Only Vignetting
REM   1: Only Color
REM   2: Both Vignetting & Color
REM 255: Default gain, gain = 1
REM ********************************************

REM ***** Set Shading Calibration Exponent *****
REM Exp value: 0~100 (0~1)
REM Default: 255
REM ********************************************

REM ****** Set Shading Calibration Target ******
REM Target value: 10~90 (0.1~0.9)
REM Default: 255
REM ********************************************

REM ******* Shading Calibration Setting ********
510 LET ClearData = NO
511 LET SaveLog   = YES
512 LET SaveImage = NO
REM ********************************************

520 FOREIGN RetCode = InitShadingCalibrPara()
521 IF RetCode == 0 THEN 530 ELSE 670
REM ***** Belowing must match with single station *****
530 FOREIGN RetCode = SetShadingCalibrPara( 0, 2, 70, 50)
531 FOREIGN RetCode = SetShadingCalibrPara( 1, 2, 60, 50)
532 FOREIGN RetCode = SetShadingCalibrPara( 2, 2, 60, 50)
533 FOREIGN RetCode = SetShadingCalibrPara( 3, 2, 50, 50)
534 FOREIGN RetCode = SetShadingCalibrPara( 12, 2, 70, 20)




545 IF RetCode == 0 THEN 550 ELSE 670

550 FOREIGN RetCode = RunShadingCalibr(ClearData, SaveLog, SaveImage)
551 IF RetCode == 0 THEN 650 ELSE 670


650 FOREIGN Ret = OneCard_FlgSet(1)
651 LET LCDPrint = "Shading Calibration Success"
652 SYSTEM ScreenString(20, 160, LCDPrint)
653 SYSTEM KeyEventEnable()
REM 653 SYSTEM delay_us(10000000)
654 FOREIGN OneCardTest(1)
REM Don't do Shading Verification
REM 655 FOREIGN Ret = OneCard_FlgSet(1)  
REM 656 GOTO 1000
REM Do Shading Verification
655 GOTO 1000

670 FOREIGN Ret = OneCard_FlgSet(0)
671 SYSTEM KeyEventEnable()
672 LET Str = "Shading Calibration Fail!!"
673 FOREIGN KeyReview(0)
674 FOREIGN Ret = OneCard_ErrPrint(Str)
675 GOTO 1000


700 LET VignettingCriteria   = 60
701 LET ColorShadingCriteria  = 15
702 LET EnShadingComp  = YES
703 LET EnSaveJpg  = NO
704 LET EnSaveLog  = YES
705 LET EnSaveImg  = NO

REM **********Workaround************
740 SYSTEM KeyHoldS1(0)
741 SYSTEM delay_us(1000000)
742 SYSTEM KeyHoldS2(0)
743 SYSTEM KeyReleaseS2(0)
744 SYSTEM KeyReleaseS1(0)
745 SYSTEM delay_us(1000000)
746 SYSTEM KeyHoldS1(0)
747 SYSTEM KeyReleaseS1(0)
748 SYSTEM delay_us(15000000)
REM **********Workaround************

758 FOREIGN RetCode = RunShadingVerify(VignettingCriteria, ColorShadingCriteria, EnShadingComp, EnSaveJpg, EnSaveLog, EnSaveImg)
759 IF RetCode == 0 THEN 760 ELSE 770
    
760 FOREIGN Ret = OneCard_FlgSet(1)  
761 LET LCDPrint = "Shading Verification Success"
762 SYSTEM ScreenString(20, 160, LCDPrint)
REM 763 SYSTEM delay_us(10000000)
764 SYSTEM KeyEventEnable() 
765 FOREIGN OneCardTest(1)
766 GOTO 1000

770 FOREIGN Ret = OneCard_FlgSet(0)
771 SYSTEM KeyEventEnable()
772 LET Str = "Shading Verification Fail"
773 FOREIGN KeyReview(0)
774 FOREIGN Ret = OneCard_ErrCodePrint(RetCode)
775 GOTO 1000





1000 END
RUN